
require.config({
	"packages": [
		{
            "name": "jquery",
            "main": "jquery.js"
        },
        {
            "name": "moment",
            "main": "moment.js"
        }
	],
	"paths":{
		"bootstrap":"../vendor/twbs/bootstrap/dist/js",
		"swal":"https://cdn.bootcss.com/limonte-sweetalert2/7.21.1/sweetalert2.all.min"
	},
	"shim":{
		"bootstrap":{
			"deps":[
				"jquery"
            ],
            "exports":"bootstrap"
		}
	},
	"baseUrl": "components"
});
//解决加载顺序问题
require(["jquery"],function($){
    require(["bootstrap/bootstrap","swal"],function(bootStrap,swal){
        $("#login").click(function(){
            //定义基本的校验规则
            var validRule=[
                {
                    id:"account",
                    title:"账号",
                    regex:/^([a-zA-z0-9]){5,12}/
                },{
                    id:"password",
                    title:"密码",
                    regex:/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{6,16}$/
                }
            ];
            var item=null,value="";
            //开始校验内容
            for($index in validRule){
                item=validRule[$index];
                value=$("#"+item.id).val();
                //非空验证
                //实际上可以由正则处理，不过这里单独处理下
                if(""==value){
                    swal({
                        title:"校验失败",
                        text:item.title+"不能为空",
                        timer:2000,
                        type:"warning",
                        showConfirmButton:false
                    });
                    return false;
                }else{
                    //校验正则
                    if(!item.regex.test(value)){
                        swal({
                            title:"校验失败",
                            text:item.title+"输入不符合规则",
                            timer:2000,
                            type:"warning",
                            showConfirmButton:false
                        });
                        return false;
                    }
                }
                //将内容写入localStorage中
                localStorage.setItem(item.id,value);
            }
            //校验通过
            location.href="main.html";
            return false;
        });
    });
});
